<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="MA响应级别" prop="responseLevel">
        <el-select
          v-model="queryParams.responseLevel"
          placeholder="请选择MA响应级别"
          clearable
        >
          <el-option
            v-for="dict in dict.type.work_order_ma_adidas_response_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="MA故障分类" prop="faultClass">
        <el-select
          v-model="queryParams.faultClass"
          placeholder="请选择MA故障分类"
          clearable
        >
          <el-option
            v-for="dict in dict.type.work_order_ma_adidas_fault_class"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="MA故障代码" prop="faultCode">
        <el-select
          v-model="queryParams.faultCode"
          placeholder="请选择MA故障代码"
          clearable
        >
          <el-option
            v-for="dict in dict.type.work_order_ma_adidas_fault_code"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="MA解决代码" prop="soluteCode">
        <el-select
          v-model="queryParams.soluteCode"
          placeholder="请选择MA解决代码"
          clearable
        >
          <el-option
            v-for="dict in dict.type.work_order_ma_adidas_solute_code"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="MA故障设备" prop="faultEquipment">
        <el-select
          v-model="queryParams.faultEquipment"
          placeholder="请选择MA故障设备"
          clearable
        >
          <el-option
            v-for="dict in dict.type.work_order_ma_adidas_fault_equipment"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:workOrderMaAdidas:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:workOrderMaAdidas:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:workOrderMaAdidas:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:workOrderMaAdidas:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="workOrderMaAdidasList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column
        label="工单号"
        align="center"
        prop="workOrderId"
        v-if="true"
      />
      <el-table-column label="工单类型" align="center" prop="workOrderType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_type"
            :value="scope.row.workOrderType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="第三方系统单号"
        align="center"
        prop="thirdSysNumber"
      />
      <el-table-column label="本单客户联系人" align="center">
        <template slot-scope="scope">
          {{ scope.row.contacts }} / {{ scope.row.contactNumber }}
        </template>
      </el-table-column>
      <el-table-column label="店铺" align="center" prop="storeNumber">
        <template slot-scope="scope">
          {{ scope.row.storeNumber }} / {{ scope.row.storeName }}/
          {{ scope.row.storeType }}
        </template>
      </el-table-column>
      <el-table-column
        label="关联的店铺地址"
        align="center"
        prop="storeAddress"
      />
      <el-table-column
        label="工单描述"
        align="center"
        prop="workOrderDescription"
      />
      <el-table-column label="工单状态" align="center" prop="workOrderStatusId">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_status"
            :value="scope.row.workOrderStatusId"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="工单响应超时"
        align="center"
        prop="workOrderResponseTimeOver"
      />
      <el-table-column
        label="工单上门超时"
        align="center"
        prop="workOrderOnsiteTimeOver"
      />
      <el-table-column
        label="工单处理超时"
        align="center"
        prop="workOrderProcessingTimeOver"
      />
      <el-table-column label="项目编号" align="center" prop="projectNumber" />
      <el-table-column label="项目名" align="center" prop="projectName" />
      <el-table-column
        label="工单子状态"
        align="center"
        prop="workOrderStatusIdChild"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_status_child"
            :value="scope.row.workOrderStatusIdChild"
          />
        </template>
      </el-table-column>
      <el-table-column label="MA响应级别" align="center" prop="responseLevel">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_ma_adidas_response_level"
            :value="scope.row.responseLevel"
          />
        </template>
      </el-table-column>
      <el-table-column label="MA故障分类" align="center" prop="faultClass">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_ma_adidas_fault_class"
            :value="scope.row.faultClass"
          />
        </template>
      </el-table-column>
      <el-table-column label="MA故障代码" align="center" prop="faultCode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_ma_adidas_fault_code"
            :value="scope.row.faultCode"
          />
        </template>
      </el-table-column>
      <el-table-column label="MA解决代码" align="center" prop="soluteCode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_ma_adidas_solute_code"
            :value="scope.row.soluteCode"
          />
        </template>
      </el-table-column>
      <el-table-column label="MA故障设备" align="center" prop="faultEquipment">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_ma_adidas_fault_equipment"
            :value="scope.row.faultEquipment"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="MA响应周期"
        align="center"
        prop="responsePeriod"
      />
      <el-table-column label="MA订单周期" align="center" prop="orderCycle" />
      <el-table-column label="MA维保周期" align="center" prop="repairCycle" />
      <el-table-column label="MA维保类别" align="center" prop="repairType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.work_order_ma_adidas_repair_type"
            :value="scope.row.repairType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:workOrderMaAdidas:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:workOrderMaAdidas:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改adidas工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目号" prop="projectId">
          <el-select v-model="form.projectId" placeholder="请选择项目">
            <el-option
              v-for="item in projectList"
              :key="item.projectId"
              :label="
                item.projectNumber +
                '#' +
                item.projectName +
                '#' +
                item.projectType
              "
              :value="item.projectId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="店铺" prop="storeId">
          <el-select v-model="form.storeId" placeholder="请选择店铺">
            <el-option
              v-for="item in storeList"
              :key="item.storeId"
              :label="
                item.storeNumber + '#' + item.storeName + '#' + item.storeType
              "
              :value="item.storeId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="店铺地址" prop="storeAddress">
          <el-input
            v-model="form.storeAddress"
            disabled
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="第三方系统单号" prop="thirdSysNumber">
          <el-input
            v-model="form.thirdSysNumber"
            placeholder="请输入第三方系统单号"
          />
        </el-form-item>
        <el-form-item label="本单客户联系人" prop="contacts">
          <el-row>
            <el-col :span="6">
              <el-input
                v-model="form.contacts"
                placeholder="请输入本单客户联系人"
              />
            </el-col>
            <el-col :span="18">
              <el-input
                v-model="form.contactNumber"
                placeholder="请输入本单客户联系电话"
              /> </el-col
          ></el-row>
        </el-form-item>

        <el-form-item label="MA响应级别" prop="responseLevel">
          <el-select
            v-model="form.responseLevel"
            placeholder="请选择MA响应级别"
          >
            <el-option
              v-for="dict in dict.type.work_order_ma_adidas_response_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="MA故障分类" prop="faultClass">
          <el-select v-model="form.faultClass" placeholder="请选择MA故障分类">
            <el-option
              v-for="dict in dict.type.work_order_ma_adidas_fault_class"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工单描述" prop="workOrderDescription">
          <el-input
            v-model="form.workOrderDescription"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWorkOrderMaAdidas,
  getWorkOrderMaAdidas,
  delWorkOrderMaAdidas,
  addWorkOrderMaAdidas,
  updateWorkOrderMaAdidas,
} from "@/api/system/workOrderMaAdidas";
import { listWorkOrderStoreAdidas } from "@/api/system/workOrderStoreAdidas";
import { listProject } from "@/api/system/project";

export default {
  name: "WorkOrderMaAdidas",
  dicts: [
    "work_order_processing",
    "work_order_status_child",
    "work_order_type",
    "work_order_status",
    "work_order_ma_adidas_repair_type",
    "work_order_ma_adidas_fault_equipment",
    "work_order_ma_adidas_response_level",
    "work_order_ma_adidas_fault_class",
    "work_order_ma_adidas_fault_code",
    "work_order_ma_adidas_solute_code",
  ],
  data() {
    return {
      //项目列表
      projectList: [],
      //店铺列表
      storeList: [],
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // adidas工单表格数据
      workOrderMaAdidasList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workOrderId: undefined,
        workOrderType: undefined,
        thirdSysNumber: undefined,
        contacts: undefined,
        contactNumber: undefined,
        storeId: undefined,
        storeNumber: undefined,
        storeName: undefined,
        storeType: undefined,
        storeAddress: undefined,
        workOrderDescription: undefined,
        processing: undefined,
        workOrderStatusId: undefined,
        workOrderResponseTimeOver: undefined,
        workOrderOnsiteTimeOver: undefined,
        workOrderProcessingTimeOver: undefined,
        projectId: undefined,
        projectNumber: undefined,
        projectName: undefined,
        workOrderStatusIdChild: undefined,
        responseLevel: undefined,
        faultDescribe: undefined,
        faultClass: undefined,
        faultCode: undefined,
        soluteCode: undefined,
        faultEquipment: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        contacts: [
          {
            required: true,
            message: "本单客户联系人不能为空",
            trigger: "blur",
          },
        ],
        responseLevel: [
          {
            required: true,
            message: "响应级别不能为空",
            trigger: "blur",
          },
        ],
        storeId: [
          { required: true, message: "店铺号不能为空", trigger: "change" },
        ],
        workOrderDescription: [
          { required: true, message: "工单描述不能为空", trigger: "blur" },
        ],
        projectId: [
          { required: true, message: "项目id不能为空", trigger: "change" },
        ],
        faultClass: [
          { required: true, message: "MA故障分类不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    //查询项目列表
    listProject().then((response) => {
      this.projectList = response.rows;
    });
    //查询店铺列表
    listWorkOrderStoreAdidas().then((res) => {
      this.storeList = res.rows;
    });
    this.getList();
  },
  methods: {
    /** 查询adidas工单列表 */
    getList() {
      this.loading = true;
      listWorkOrderMaAdidas(this.queryParams).then((response) => {
        this.workOrderMaAdidasList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        workOrderId: undefined,
        workOrderType: undefined,
        thirdSysNumber: undefined,
        contacts: undefined,
        contactNumber: undefined,
        storeId: undefined,
        storeNumber: undefined,
        storeName: undefined,
        storeType: undefined,
        storeAddress: undefined,
        workOrderDescription: undefined,
        workOrderStatusId: undefined,
        workOrderStatus: undefined,
        workOrderResponseTimeOver: undefined,
        workOrderOnsiteTimeOver: undefined,
        workOrderProcessingTimeOver: undefined,
        projectId: undefined,
        projectNumber: undefined,
        projectName: undefined,
        updateTime: undefined,
        updateBy: undefined,
        createTime: undefined,
        createBy: undefined,
        delFlag: undefined,
        workOrderStatusIdChild: undefined,
        workOrderStatusChild: undefined,
        responseLevel: undefined,
        faultDescribe: undefined,
        faultClass: undefined,
        faultCode: undefined,
        soluteCode: undefined,
        faultEquipment: undefined,
        responsePeriod: undefined,
        orderCycle: undefined,
        repairCycle: undefined,
        repairType: undefined,
        updateTime: undefined,
        updateBy: undefined,
        createTime: undefined,
        createBy: undefined,
        delFlag: undefined,
        methodName: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.workOrderId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.workOrderType = "MA";
      this.form.workOrderStatusId = "10";
      this.open = true;
      this.title = "添加adidas工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const workOrderId = row.workOrderId || this.ids;
      getWorkOrderMaAdidas(workOrderId).then((response) => {
        this.loading = false;
        this.form = response.data;
        this.form.methodName = "update"
        this.open = true;
        this.title = "修改adidas工单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.workOrderId != null) {
            updateWorkOrderMaAdidas(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addWorkOrderMaAdidas(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const workOrderIds = row.workOrderId || this.ids;
      this.$modal
        .confirm('是否确认删除adidas工单编号为"' + workOrderIds + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delWorkOrderMaAdidas(workOrderIds);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/workOrderMaAdidas/export",
        {
          ...this.queryParams,
        },
        `workOrderMaAdidas_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
